//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package pxb.android.zipalign;

import pxb.android.Res_value;
import pxb.android.axml.Axml;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;

public class AxmlFastZipOut extends FastZipOut {
    private boolean nativeLibraryStore4K = false;

    public AxmlFastZipOut(File out) throws IOException {
        super(out);
    }

    public void initByAndroidManifestContent(Axml axml) {
        Axml.Node manifest = axml.findFirst("manifest");
        if (manifest != null) {
            Axml.Node application = manifest.findFirst("application");
            if (application != null) {
                Axml.Node.Attr attr = application.findFirstAttr(16844010);
                if (attr != null) {
                    Res_value v = attr.value;
                    if (v.type == 18) {
                        this.setNativeLibraryStore4K(v.data == 0);
                    }
                }
            }

            Axml.Node usessdk = manifest.findFirst("uses-sdk");
            if (usessdk != null) {
                Axml.Node.Attr attr = usessdk.findFirstAttr(16843376);
                if (attr != null) {
                    Res_value v = attr.value;
                    if (v.type >= 16 && v.type <= 31) {
                        this.setTargetSdk(v.data);
                    }
                }
            }
        }

    }

    public void initByAndroidManifestContent(ByteBuffer b) throws IOException {
        this.initByAndroidManifestContent(Axml.parse(b));
    }

    protected boolean isStorage4K(FastZipEntry e) {
        if (this.nativeLibraryStore4K) {
            String name = e.utf8Name();
            if (name.endsWith(".so") && name.startsWith("lib/")) {
                return true;
            }
        }

        return false;
    }

    public void setNativeLibraryStore4K(boolean storeNativeLibraryStore4K) {
        this.nativeLibraryStore4K = storeNativeLibraryStore4K;
    }
}
